#include "stm32f10x.h"                  // Device header
#include "LED.h"
#include "Delay.h"


/*
读取字节
*/
uint8_t MyFLASH_ReadByte(uint32_t Address)
{
	return *((__IO uint8_t *)(Address));
}

/*
读取半字
*/
uint16_t MyFLASH_ReadHalfWord(uint32_t Address)
{
	return *((__IO uint16_t *)(Address));
}

/*
读取全字
*/
uint32_t MyFLASH_ReadWord(uint32_t Address)
{
	return *((__IO uint32_t *)(Address));
}

/*
全擦除函数
*/
void MyFLASH_EraseAllPages(void)
{
	FLASH_Unlock();
	if (FLASH_EraseAllPages() == FLASH_COMPLETE)
	{
		LED2_ON();				// 擦除程序都销毁了, 所以亮不了灯啊孩子
		Delay_ms(2000);
	}
	FLASH_Lock();
}

/*
页擦除函数
*/
void MyFlashErasePage(uint32_t PageAddress)
{
	FLASH_Unlock();
	if (FLASH_ErasePage(PageAddress) == FLASH_COMPLETE)
	{
//		LED1_ON();
		Delay_ms(2000);
	}
	else{LED1_ON();}
	FLASH_Lock();
}

/*
页编程函数(写入全字)
*/
void MyFLASH_ProgramWord(uint32_t Address, uint32_t Data)
{
	FLASH_Unlock();
	FLASH_ProgramWord(Address, Data);
	FLASH_Lock();
}

/*
页编程函数(写入全字)
*/
void MyFLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
{
	FLASH_Unlock();
	FLASH_ProgramHalfWord(Address, Data);
	FLASH_Lock();
}
